﻿using MediatR;
using T_Person.APi.Applation.CommandHandlers.EmployeeHandlers;
using T_Person.BaseRep.Interface;

namespace T_Person.APi.Applation.Commands.EmployeeCommand
{
    public class EmployeeDeleteCommand : IRequestHandler<EmployeeDeleteHandler, int>
    {
        private readonly IEmployeeRep employeeRep;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="employeeRep"></param>
        public EmployeeDeleteCommand(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }
        /// <summary>
        /// 删除方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(EmployeeDeleteHandler request, CancellationToken cancellationToken)
        {
            var list = await employeeRep.GetAloneByid(request.id);
            list.IsDel = true;
            list.UpdateDate = DateTime.Now;
            list.UpdateBy = "小红";
            return await employeeRep.Update(list);
        }
    }
}
